package companyTest.huawei;

import java.util.*;

public class Code2copy {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        int start=s.nextInt();
        int end=s.nextInt();
        Map<Integer, Node>map=new HashMap<>();
        Queue<Node>queue=new ArrayDeque<>();
        for (int i = start; i <= end; i++) {
            Node node=new Node();
            node.index=i;
            node.isUsed=false;
            map.put(i,node);
            queue.offer(node);
        }


        int time=s.nextInt();
        for (int i = 0; i < time; i++) {
            int opt=s.nextInt();//操作符
            int index=s.nextInt();//操作的节点下标或者动态分配的个数
            switch (opt){
                //动态分配
                case 1:
                    for (int j = 0; j <index; j++) {
                        if (!queue.isEmpty()){
                            Node node=queue.poll();
                            if (node.isUsed)j--;
                            node.isUsed=true;
                        }
                    }
                    break;
                case 2:
                    Node node = map.get(index);
                    if (!node.isUsed){
                        node.isUsed=true;
                    }
                    break;
                case 3:

                    Node node23 = map.get(index);
                    if (node23.isUsed){
                        queue.offer(node23);
                        node23.isUsed=false;
                    }
                    break;
            }
        }
        while (!queue.isEmpty()){
            if (queue.peek().isUsed){
                queue.poll();
            }else {
                System.out.println(queue.peek().index);
                break;
            }
        }
    }
}
class Node {
    int index;
    boolean isUsed;
}
